import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ImportTemplateParams, ApprovalInitTemplateResult, SubmitApprovalConfigParams } from './types';

/**
 * 初始化审核信息 - 检查是否已配置过审核流程并获取完整数据
 * @param params 初始化参数
 */
export const initApprovalTemplate = (params: { businessType: string; businessId: string | number }): AxiosPromise<ApprovalInitTemplateResult> => {
  return request({
    url: '/approval/instance/init',
    method: 'get',
    params: params
  });
};

/**
 * 提交审核（模板或自定义）
 * @param data 审核数据
 */
export const submitApproval = (data: SubmitApprovalConfigParams): AxiosPromise<{ data: boolean }> => {
  return request({
    url: '/approval/instance/submit',
    method: 'post',
    data: data
  });
};

/**
 * 自动导入模板并初始化审核信息（分离事务的方式）
 * @param data 导入参数
 */
export const autoImportTemplate = (data: ImportTemplateParams): AxiosPromise<ApprovalInitTemplateResult> => {
  return request({
    url: '/approval/instance/autoImport',
    method: 'post',
    data: data
  });
};


/**
 * 重置审核状态（远程调用专用）
 * @param businessType 业务类型
 * @param businessId 业务ID
 * @param approvalStatus 审核状态
 */
export function resetApprovalStatus(businessType: string, businessId: number, approvalStatus: string) {
  return request({
    url: '/approval/remote/resetStatus',
    method: 'put',
    params: {
      businessType,
      businessId,
      approvalStatus,
    },
  })
}
